package com.jishuo.nontax.bfc.service;


import com.jishuo.nontax.bean.vo.SelectQueueVO;
import com.jishuo.nontax.bfc.dao.ParameterMapper;
import com.jishuo.nontax.bfc.tlq.CertAndQueue;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

@Slf4j
@Service
public class ParameterService {

    @Resource
    private ParameterMapper parameterMapper;


    public void selectFselecertandqueue() {
        try{
            CertAndQueue.CACERTID = new HashMap<String,String>();
            CertAndQueue.SIGNCACERTID = new HashMap<String,String>();
            CertAndQueue.RECEIVECACERTID = new HashMap<String,String>();
            CertAndQueue.RECEIVESIGNCACERTID = new HashMap<String,String>();
            CertAndQueue.TLQQUEUE = new HashMap<String,String>();
            CertAndQueue.RECEIVEQUEUE = new HashMap<String,String>();
            CertAndQueue.ISENCRYPT = new HashMap<String,String>();
            CertAndQueue.RECEIVEISENCRYPT = new HashMap<String,String>();
            List<SelectQueueVO> selectQueueVO = parameterMapper.selectFselecertandqueue(0);
            for (SelectQueueVO queueVO : selectQueueVO) {
                CertAndQueue.RECEIVECACERTID.put(queueVO.getReceives(),queueVO.getCertid());
                CertAndQueue.RECEIVESIGNCACERTID.put(queueVO.getReceives(),queueVO.getSigncertid());
                CertAndQueue.RECEIVEQUEUE.put(queueVO.getReceives(),queueVO.getSends());
                CertAndQueue.RECEIVEISENCRYPT.put(queueVO.getReceives(),queueVO.getIsencrypt().toString());

            }

            List<SelectQueueVO> selectQueueVO1 = parameterMapper.selectFselecertandqueue(1);
            for (int i = 0; i < selectQueueVO1.size(); i++) {
                SelectQueueVO queueVO = selectQueueVO1.get(i);
                CertAndQueue.CACERTID.put(Integer.toString(i),queueVO.getCertid());
                CertAndQueue.SIGNCACERTID.put(Integer.toString(i),queueVO.getSigncertid());
                CertAndQueue.TLQQUEUE.put(Integer.toString(i),queueVO.getSends());
                CertAndQueue.ISENCRYPT.put(Integer.toString(i),queueVO.getIsencrypt().toString());
            }
        }catch(Exception e){
            log.info("初始化证书和返回队列配置时出错"+e.toString());
        }
    }
}
